package com.ssm.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.blog.dao.PhotoDAO;
import com.ssm.blog.pojo.Photo;
import com.ssm.blog.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PhotoServiceImpl implements PhotoService {
    @Autowired
    private PhotoDAO photoDAO;

    @Override
    public void addPhoto(Photo photo) {
        photoDAO.addPhoto(photo);
    }

    @Override
    public PageInfo<Photo> getPhotoList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize, "id desc");
        List<Photo> photoList = photoDAO.getPhotoList();
        PageInfo<Photo> page = new PageInfo<>(photoList);
        return page;
    }

    @Override
    public void deletePhotoById(Integer id) {
        photoDAO.deletePhotoById(id);
    }
}
